﻿/**
 * 地图
 */
(function(E){
var Consts = E.consts, win;

E.plugin("GoogleMap", {
	language: 'zh-cn',
	config:{
		width: 600,
		height:360,
		position: 'center',
		overlay: true
	},
	
	// 在插件初始化时执行
	init: function( self ){
		self.cache['html'] = '<div id="GoogleMap" class="jqe-plugin-googlemap" style="margin:5px 0"></div>';
	},
	
	iframeLoad: function( obj ){
		win = obj.win;
	},
	
	one: function(panel, self){
		panel.find(".jqe-plugin-googlemap").html('<iframe frameborder="0" name="iframe_GoogleMap" tabindex="0" style="width: 100%; height: 350px; margin:0px; " scrolling="no" src="'+E.config('jqePath')+'/plugin_html/GoogleMap.html"></iframe>');
	},
	get: function( panel, self ){
		var Main = win.Main,
			geocoder = Main.geocoder,
			map = Main.map,
			center = map.getCenter().lat() + ',' + map.getCenter().lng(),
			marker = Main.marker ? Main.marker.position : center,
			zoom = map.getZoom(),
			maptype = map.getMapTypeId(),
			// http://maps.googleapis.com/maps/api/staticmap
			src = 'http://maps.google.com/maps/api/staticmap'
				+ '?center=' + center
				+ '&zoom=' + zoom
				+ '&size=520x340'
				+ '&maptype=' + maptype
				+ '&markers=' + marker
				+ '&language=' + self.language
				+ '&sensor=false',
			html = '<img class="googlemap" src="'+ src +'" title="'+Main.address+'" alt="'+Main.address+'"/>';
		return html;
	}
});

})(jQEditor);